/**
 * 日志等级
 */
export type LogLevel = "info" | "warn" | "error";

/**
 * 记录日志
 * @param msg 日志内容
 * @param level 日志等级 默认为 error
 */
export const logger = (message: string, level: LogLevel = "error") => {
    const loggerMap = {
        info: (message: string) => {
            // eslint-disable-next-line no-console
            console.info(message);
        },
        warn: (message: string) => {
            // eslint-disable-next-line no-console
            console.warn(message);
        },
        error: (message: string) => {
            // eslint-disable-next-line no-console
            console.error(message);
        }
    };
    const fn = loggerMap[level];
    if (!fn) {
        throw new Error(`Invalid log level: ${level}`);
    }
    fn(message);
};
